package com.hmall.user.enums;

import lombok.Getter;

@Getter
public enum CodeEnum {

    Yes(0,"是"),
    No(1,"否")
    ;

    private int value;
    private String desc;

    CodeEnum(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static CodeEnum getByValue(int value) {
        for (CodeEnum codeEnum : CodeEnum.values()) {
            if (codeEnum.getValue() == value) {
                return codeEnum;
            }
        }
        throw new IllegalArgumentException("枚举值不正确");
    }

    public static CodeEnum getByDesc(String desc) {
        for (CodeEnum codeEnum : CodeEnum.values()) {
            if (codeEnum.getDesc().equals(desc)) {
                return codeEnum;
            }
        }
        throw new IllegalArgumentException("枚举值不正确");
    }

}
